<template>
    <div id="login-page">
        <div class="login-container">
            <div class="login-main">
                <div class="login-top">
                    <span>爱购登录</span>
                    <span class="bg1"></span>
                    <span class="bg2"></span>
                </div>
                <el-card>
                    <el-form :model="loginForm" ref="loginForm" class="login-bottom" :rules="rules">
                        <div class="center">
                            <el-form-item prop="userName">
                                <el-input type="text" v-model="loginForm.userName" auto-complete="off" placeholder="账号">
                                </el-input>
                            </el-form-item>
                            <el-form-item  prop="passWord">
                                <el-input type="password" v-model="loginForm.passWord" show-password auto-complete="off"
                                @keyup.enter.native="login('loginForm')"
                                    placeholder="密码">
                                </el-input>
                            </el-form-item>
                        </div>
                        <el-form-item style="width: 100%">
                            <el-button class="login-btn" type="primary" @click="login('loginForm')">登录</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>
        </div>
    </div>

</template>

<script>
export default {
    data() {
        return {
            loginForm: {
                userName: "",
                passWord: "",
            },
            responseResult: [],
            rules: {
                userName: [
                    { required: true, message: '请输入账户', trigger: 'blur' },
                ],
                passWord: [
                    { required: true, message: '请输入密码'}
                ],
            }
        };
    },
    methods: {
        login(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$http.post('login',this.$qs.stringify(this.loginForm))
                    .then(resp => {
                        const { data } = resp
                        //处理后台返回的结果
                        localStorage.setItem("user",JSON.stringify(data.data))
                        if(data.data) {
                            this.$message({
                                message: data.data.user_name + '登录成功',
                                type: 'success'
                            });
                            this.$router.push({path:"/console/1-1"})
                        }else {
                            this.$message.error('登录失败,账户密码错误');
                        }
                    }).catch(() => {
                        this.$message.error('登录失败,账户密码错误');
                    })
                }else {
                    this.$message.error('账户密码不能为空');
                }
            })

        }
    },
    mounted() {
    },
};
</script>


<style scoped>
#login-page {
    background: url("@/assets/img/bg.jpg") no-repeat;
    background-position: center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
}


.login-container {
    top: 50%;
    left: 50%;
    position: absolute;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    overflow: hidden;
}

.login-main {
    width: 428px;
    position: relative;
    float: left;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.login-top {
    height: 80px;
    background-color: #1E9FFF;
    border-radius: 12px 12px 0 0;
    font-family: SourceHanSansCN-Regular;
    font-size: 30px;
    font-weight: 400;
    font-stretch: normal;
    letter-spacing: 0;
    color: #fff;
    line-height: 80px;
    text-align: center;
    overflow: hidden;
    -webkit-transform: rotate(0);
    -moz-transform: rotate(0);
    -ms-transform: rotate(0);
    -o-transform: rotate(0);
    transform: rotate(0);
}

.login-top .bg1 {
    display: inline-block;
    width: 74px;
    height: 74px;
    background: #fff;
    opacity: .1;
    border-radius: 0 74px 0 0;
    position: absolute;
    left: 0;
    top: 43px;
}

.login-top .bg2 {
    display: inline-block;
    width: 94px;
    height: 94px;
    background: #fff;
    opacity: .1;
    border-radius: 50%;
    position: absolute;
    right: -16px;
    top: -16px;
}


.login-main .login-bottom {
    width: 428px;
    background: #fff;
    border-radius: 0 0 12px 12px;
    padding-bottom: 30px;
}

.login-main .login-bottom .center {
    width: 280px;
    margin: 0 auto;
    padding-top: 20px;
    padding-bottom: 15px;
    padding-right: 40px;
    overflow: hidden;
    position: relative;
}


.login-main .login-bottom .login-btn {
    width: 280px;
    height: 40px;
    position: absolute;
    background-color: #1E9FFF;
    border-radius: 16px;
    left: 50%;
	margin-left: -160px;
    text-align: center;
    color: #fff;
    font-size: 14px;
    letter-spacing: 0;
    cursor: pointer;
    border: none;
}
</style>